package com.arpa.oms.service.impl;

import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.arpa.ntocc.common.common.cache.PartyCache;
import com.arpa.ntocc.common.common.exception.ServiceException;
import com.arpa.ntocc.common.common.util.CommonUtil;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.oms.domain.dto.OmsAllocationDTO;
import com.arpa.oms.domain.dto.OmsAllocationItemDTO;
import com.arpa.oms.domain.entity.*;
import com.arpa.oms.domain.vo.OmsAllocationItemVO;
import com.arpa.oms.domain.vo.OmsAllocationVO;
import com.arpa.oms.mapper.OmsAllocationMapper;
import com.arpa.oms.service.*;
import com.arpa.wms.cache.GoodsCache;
import com.arpa.wms.cache.WarehouseCache;
import com.arpa.wms.common.util.OrderIdGeneratorUtil;
import com.arpa.wms.domain.entity.*;
import com.arpa.wms.domain.enums.AllocationStatusEnum;
import com.arpa.wms.service.IDeliveryService;
import com.arpa.wms.service.IReceiveItemService;
import com.arpa.wms.service.IReceiveService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.arpa.wms.domain.consts.CommonConst.LOCATION_MANAGEMENT;
import static com.arpa.wms.domain.consts.NumConst.NUM_ONE;
import static com.arpa.wms.domain.consts.NumConst.NUM_ZERO;

/**
 * <p>
 * OMS调拨单 服务实现类
 * </p>
 *
 * @author LEO
 * @since 2020-11-17
 */
//@Service
@Log4j2(topic = "business")
public class OmsAllocationServiceImpl extends ServiceImpl<OmsAllocationMapper, OmsAllocation> implements IOmsAllocationService {

    @Autowired
    private PartyCache partyCache;
    @Autowired
    private IOmsAllocationItemService omsAllocationItemService;
    @Autowired
    private IOmsOutboundService omsOutboundService;
    @Autowired
    private IOmsInboundService omsInboundService;
    @Autowired
    @Lazy
    private IDeliveryService deliveryService;
    @Autowired
    @Lazy
    private IReceiveService receiveService;
    @Autowired
    private IReceiveItemService receiveItemService;
    @Autowired
    private WarehouseCache warehouseCache;
    @Autowired
    private GoodsCache goodsCache;
    @Autowired
    private IOmsInventoryService omsInventoryService;

    /**
     * 保存
     * @param entity
     * @return
     */
    @Override
    @Transactional(rollbackFor={Exception.class})
    public boolean save(OmsAllocation entity) {
        //调出仓库与调入仓库不能一样
        if (entity.getSourceWarehouseCode().equals(entity.getTargetWarehouseCode())) {
            throw new ServiceException("调出仓库与调入仓库不能相同！！！");
        }
        //检查提交的是否有重复的明细
        CheckDuplicatedata(entity);
        if(StringUtils.isBlank(entity.getCode())){
            entity.setCode(OrderIdGeneratorUtil.generatorOmsOrderId(OrderIdGeneratorUtil.OrderTypeEnum.DB, "",UserUtil.getBranchCode()));
            entity.setGroupCode(UserUtil.getBranchCode());
            entity.setCreatedBy(UserUtil.getCode());
            entity.setCreatedName(partyCache.translate(UserUtil.getCode()));
            entity.setGmtCreated(LocalDateTime.now());
        }

        this.saveItem(entity);
        //汇总调拨主单单位数量
        BigDecimal unitQuantity = entity.getAllocationItemList().stream().map(OmsAllocationItem::getUnitQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
        //汇总调拨主单基本单位数量
        BigDecimal quantity = entity.getAllocationItemList().stream().map(OmsAllocationItem::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
        entity.setUnitQuantity(unitQuantity);
        entity.setQuantity(quantity);
        return super.save(entity);
    }

    /**
     * 根据code更新实体
     * @param entity
     * @return
     */
    @Override
    @Transactional(rollbackFor={Exception.class})
    public int updateByCode(OmsAllocation entity) {
        if(StringUtils.isBlank(entity.getModifiedBy())){
            entity.setModifiedBy(UserUtil.getCode());
            entity.setModifiedName(partyCache.translate(UserUtil.getCode()));
        }
        //删除调拨单明细
        List<String> deleteCodes = entity.getDeleteCodes();
        if (IterUtil.isNotEmpty(deleteCodes)) {
            omsAllocationItemService.remove(new QueryWrapper<OmsAllocationItem>().lambda().in(OmsAllocationItem::getCode, deleteCodes));
        }
        this.saveItem(entity);
        BigDecimal unitQuantity = entity.getAllocationItemList().stream().map(OmsAllocationItem::getUnitQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal quantity = entity.getAllocationItemList().stream().map(OmsAllocationItem::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
        entity.setUnitQuantity(unitQuantity);
        entity.setQuantity(quantity);
        return baseMapper.update(entity,new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, entity.getCode()));
    }

    /**
     * 查询列表
     * @param omsAllocationDTO
     * @return
     */
    @Override
    public List<OmsAllocationVO> queryList(OmsAllocationDTO omsAllocationDTO){
        //排序字段名需要驼峰转数据库下划线类型字段名
        if(StringUtils.isNotEmpty(omsAllocationDTO.getSortField())){
            omsAllocationDTO.setSortField(CommonUtil.camel2Underline(omsAllocationDTO.getSortField()));
        }
        List<OmsAllocationVO> omsAllocationVOList = baseMapper.queryList(omsAllocationDTO);
        return omsAllocationVOList;
    }

    /**
     * 查询合计,包含总数
     * @param omsAllocationDTO
     * @return
     */
    @Override
    public OmsAllocationVO queryListSum(OmsAllocationDTO omsAllocationDTO){
        OmsAllocationVO omsAllocationVO = baseMapper.queryListSum(omsAllocationDTO);
        return omsAllocationVO;
    }

    @Override
    public OmsAllocationVO getOneByCode(String code) {
        OmsAllocation omsAllocation = this.getOne(new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, code));
        if (ObjectUtil.isNull(omsAllocation)) {
            log.error("调拨单【{}】不存在", code);
            throw new ServiceException("调拨单: " + code + "不存在！");
        }
        OmsAllocationVO omsAllocationVO = new OmsAllocationVO();
        BeanUtils.copyProperties(omsAllocation, omsAllocationVO);

        OmsAllocationItemDTO omsAllocationItemDTO = new OmsAllocationItemDTO();
        omsAllocationItemDTO.setAllocationCode(code);
        omsAllocationItemDTO.setPageSize(Integer.MAX_VALUE);
        // 获取调拨单明细信息
        List<OmsAllocationItemVO> omsAllocationItemVOList = omsAllocationItemService.queryList(omsAllocationItemDTO);
        omsAllocationVO.setAllocationItemList(omsAllocationItemVOList);
        Warehouse warehouseCacheObj = warehouseCache.getObj(omsAllocation.getTargetWarehouseCode());
        omsAllocationVO.setContacts(warehouseCacheObj.getContacts());
        omsAllocationVO.setPhoneNumber(warehouseCacheObj.getPhoneNumber());
        omsAllocationVO.setAddress(warehouseCacheObj.getAddress());

        return omsAllocationVO;
    }

    /**
     * 审核 调拨单
     * @param omsAllocation
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int audit(OmsAllocation omsAllocation) {
        OmsAllocation allocation = this.getOne(new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, omsAllocation.getCode()));
        if (ObjectUtil.isNull(allocation)) {
            log.error("调拨单【{}】不存在", omsAllocation.getCode());
            throw new ServiceException("调拨单：" + omsAllocation.getCode() + "不存在！");
        }

        List<OmsAllocationItem> omsAllocationItemList = omsAllocationItemService.list(new QueryWrapper<OmsAllocationItem>().lambda().eq(OmsAllocationItem::getAllocationCode, allocation.getCode()));
        omsAllocationItemList.stream().forEach(item -> {
            OmsInventory omsInventory = omsInventoryService.hasSameInventory(item.getGoodsCode(), allocation.getSourceWarehouseCode(), allocation.getShipmentCode());
            //获取库存平均单价
            if (ObjectUtil.isNotNull(omsInventory)) {
                item.setAverageUnitPrice(omsInventory.getAverageUnitPrice());
            }

        });
        allocation.setAllocationItemList(omsAllocationItemList);

        // 审核通过才需要生成后续的出库单、入库单等
        if (AllocationStatusEnum.PASS.getValue().equals(omsAllocation.getStatus())) {
            handleLocationManagement(omsAllocation, allocation, omsAllocationItemList);
        }
        // 更新 调拨单
        omsAllocation.setGmtVerify(LocalDateTime.now());
        omsAllocation.setVerifyBy(UserUtil.getCode());
        omsAllocation.setVerifyName(partyCache.translate(UserUtil.getCode()));
        omsAllocation.setModifiedBy(UserUtil.getCode());
        omsAllocation.setModifiedName(partyCache.translate(UserUtil.getCode()));
        return baseMapper.update(omsAllocation, new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, omsAllocation.getCode()));
    }

    /**
     * 作废 调拨单
     * @param code
     * @return
     */
    @Override
    public int invalid(String code) {
        OmsAllocation omsAllocation = new OmsAllocation();
        omsAllocation.setCode(code);
        omsAllocation.setStatus(AllocationStatusEnum.INVALID.getValue());
        return baseMapper.update(omsAllocation, new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, code));
    }

    /**
     * 根据发货单更新调拨单以及生成OMS出库单
     * @param deliveryCode
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateAllocation(String deliveryCode, Outbound outbound, Map<String, BigDecimal[]> sourceItemOutQuantity) {
        String groupCode = outbound.getGroupCode();
        Delivery delivery = deliveryService.getOne(new QueryWrapper<Delivery>().lambda()
                .eq(Delivery::getCode, deliveryCode)
                .eq(Delivery::getGroupCode,groupCode));
        // 调出仓调拨单信息
        OmsAllocation omsAllocation = getOne(new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, delivery.getSourceCode()));
        // 更新调拨单出库数量
        omsAllocation.setUnitOutboundQuantity(delivery.getSendNum());
        updateById(omsAllocation);

        // 根据出库单明细更新调出仓调拨单明细
        sourceItemOutQuantity.forEach((sourceItemCode, outQuantities) -> {
            omsAllocationItemService.update(new UpdateWrapper<OmsAllocationItem>().lambda().eq(OmsAllocationItem::getCode, sourceItemCode)
                    .setSql(" outbound_quantity = outbound_quantity + " + outQuantities[NUM_ZERO])
                    .setSql(" unit_outbound_quantity = unit_outbound_quantity + " + outQuantities[NUM_ONE]));
        });
    }


    /**
     * wms发货流程完全完成进行的操作，生成下一个仓库的收货单或oms入库单
     * @param sourceCode
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void afterWmsFinishAllOutbound(String sourceCode) {
        // 调出仓调拨单信息
        OmsAllocation omsAllocation = getOne(new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, sourceCode));
        List<OmsAllocationItem> omsAllocationItems;
        Map<String, Object> targetWarehouseCacheMap = warehouseCache.get(omsAllocation.getTargetWarehouseCode());
        // 根据调入仓是否启用库位管理来生成不同的单据
        if (NUM_ZERO.equals(targetWarehouseCacheMap.get(LOCATION_MANAGEMENT))) {
            // 调入仓未启用库位管理，则生成oms入库单
            // 更新调拨明细的入库数量，因为会直接生成oms的入库单，入库明细需要获取入库数量，入库数量等于实际出库数量
            omsAllocationItemService.update(new UpdateWrapper<OmsAllocationItem>().lambda().eq(OmsAllocationItem::getAllocationCode, omsAllocation.getCode())
                    .setSql(" inbound_quantity = outbound_quantity ").setSql(" unit_inbound_quantity = unit_outbound_quantity "));
            omsAllocationItems = omsAllocationItemService.list(new QueryWrapper<OmsAllocationItem>().lambda()
                    .eq(OmsAllocationItem::getAllocationCode, omsAllocation.getCode()));
            omsAllocation.setAllocationItemList(omsAllocationItems);

            omsInboundService.saveByOmsAllocation(omsAllocation, null);
        } else if (NUM_ONE.equals(targetWarehouseCacheMap.get(LOCATION_MANAGEMENT))) {
            // 调入仓启用库位管理，则生成调入仓的收货单
            omsAllocationItems = omsAllocationItemService.list(new QueryWrapper<OmsAllocationItem>().lambda()
                    .eq(OmsAllocationItem::getAllocationCode, omsAllocation.getCode()));
            omsAllocation.setAllocationItemList(omsAllocationItems);
            receiveService.saveByOmsAllocation(omsAllocation);
        }
    }

    /**
     * wms流程生成oms出库单
     *
     * @param sourceCode
     * @param outbound
     * @param sourceItemOutQuantity
     */
    @Override
    public void wmsSaveOmsOutboundByAllocation(String sourceCode, Outbound outbound, Map<String, BigDecimal[]> sourceItemOutQuantity) {
        OmsAllocation allocation = getOne(new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, sourceCode));
        List<OmsAllocationItem> omsAllocationItems = omsAllocationItemService.list(new QueryWrapper<OmsAllocationItem>().lambda()
                .eq(OmsAllocationItem::getAllocationCode, allocation.getCode()));
        allocation.setAllocationItemList(omsAllocationItems);
        omsOutboundService.saveByOmsAllocationForWms(allocation, outbound, sourceItemOutQuantity);
    }
    @Override
    public void wmsSaveOmsOutboundByAllocationOutBound(String sourceCode, Outbound outbound) {
        OmsAllocation allocation = getOne(new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, sourceCode));
        List<OmsAllocationItem> omsAllocationItems = omsAllocationItemService.list(new QueryWrapper<OmsAllocationItem>().lambda()
                .eq(OmsAllocationItem::getAllocationCode, allocation.getCode()));
        allocation.setAllocationItemList(omsAllocationItems);
        omsOutboundService.saveByOmsAllocationForWmsOutBound(allocation, outbound);
    }

    /**
     * 根据收货单更新调拨单以及生成OMS入库单
     * @param receiveCode
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateAllocationAndCreateOmsInbound(String receiveCode,Putaway putaway) {
        Receive receive = receiveService.getOne(new QueryWrapper<Receive>().lambda().eq(Receive::getCode, receiveCode));
        OmsAllocation omsAllocation = this.getOne(new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, receive.getSourceCode()));
        //更新调拨单收货数量
        omsAllocation.setUnitInboundQuantity(receive.getInboundQuantity());
        omsAllocation.setInboundQuantity(receive.getInboundQuantity());

        List<ReceiveItem> receiveItemList = receiveItemService.list(new QueryWrapper<ReceiveItem>().lambda().eq(ReceiveItem::getReceiveCode, receiveCode));
        List<OmsAllocationItem> omsAllocationItemList = receiveItemList.stream().map(item -> {
            Goods goods = goodsCache.getObj(item.getGoodsCode());
            // 计算出基本单位出库数量
            BigDecimal basicUnitQuantity = item.getInboundQuantity().multiply(item.getUnitConvertQuantity()).setScale(goods.getUnitPrecision().intValue(), BigDecimal.ROUND_HALF_UP);
            OmsAllocationItem omsAllocationItem = omsAllocationItemService.getOne(new QueryWrapper<OmsAllocationItem>().lambda().eq(OmsAllocationItem::getCode, item.getSourceItemCode()));
            omsAllocationItem.setInboundQuantity(basicUnitQuantity);
            omsAllocationItem.setUnitInboundQuantity(item.getInboundQuantity());
            return omsAllocationItem;
        }).collect(Collectors.toList());
        omsAllocation.setAllocationItemList(omsAllocationItemList);
        omsInboundService.saveByOmsAllocation(omsAllocation,putaway);
        omsAllocationItemService.saveOrUpdateBatch(omsAllocationItemList);
        baseMapper.update(omsAllocation, new QueryWrapper<OmsAllocation>().lambda().eq(OmsAllocation::getCode, omsAllocation.getCode()));
    }

    /**
     * 新增、修改明细
     * @param entity
     */
    private void saveItem(OmsAllocation entity) {
        String userCode = UserUtil.getCode();
        String userName = partyCache.translate(userCode);
        entity.getAllocationItemList().forEach(r -> {
            if (StrUtil.isEmpty(r.getCode())) {
                r.setCode(IdUtil.simpleUUID());
                r.setAllocationCode(entity.getCode());
                r.setQuantity(r.getUnitQuantity());
//                r.setQuantity(r.getUnitQuantity().multiply(r.getUnitConvertQuantity()));
                r.setCreatedBy(userCode);
                r.setCreatedName(userName);
                r.setGmtCreated(LocalDateTime.now());
            } else {
                r.setQuantity(r.getUnitQuantity());
//                r.setQuantity(r.getUnitQuantity().multiply(r.getUnitConvertQuantity()));
                r.setModifiedBy(userCode);
                r.setModifiedName(userName);
            }
            //todo 这里先将单位名称设置为基本单位名称，后期单位需要优化
            r.setUnitName(r.getBasicUnitName());
        });

        // 批量保存或修改调拨单明细
        omsAllocationItemService.saveOrUpdateBatch(entity.getAllocationItemList());
    }

    /**
     * 校验库存是否有足够数量支持调拨单
     * @param entity
     */
    @Transactional(rollbackFor = {Exception.class})
    public void validAllocationInventory(OmsAllocation entity) {
        // 遍历明细，如果库存数量少于调拨量，则抛出异常
        log.info("入参entity为>>>{}",entity);
        entity.getAllocationItemList().stream().forEach(e->{
            OmsInventory omsInventory = omsInventoryService.hasSameInventory(e.getGoodsCode(), entity.getSourceWarehouseCode(), entity.getShipmentCode());
            log.info("查询出的库存为>>>{}",omsInventory);
            if (omsInventory == null) {
                throw new ServiceException("商品“" + e.getGoodsName() + "”可用库存不足。");
            }
            //可用库存=总库存-占用库存-不可用库存
            BigDecimal usefulInventory = omsInventory.getQuantity().subtract(omsInventory.getUseQuantity()).subtract(omsInventory.getContUseQuantity());
            if (usefulInventory.compareTo(e.getUnitQuantity()) < 0) {
                throw new ServiceException("商品“" + e.getGoodsName() + "”可用库存不足。");
            }
        });
    }

    /**
     * 根据是否启用库位管理处理相应逻辑
     * @param omsAllocation
     * @param allocation
     * @param omsAllocationItemList
     */
    private void handleLocationManagement(OmsAllocation omsAllocation, OmsAllocation allocation, List<OmsAllocationItem> omsAllocationItemList) {
        Map<String, Object> sourceWarehouseCacheMap = warehouseCache.get(allocation.getSourceWarehouseCode());
        Map<String, Object> targetWarehouseCacheMap = warehouseCache.get(allocation.getTargetWarehouseCode());
        // 调入、调出仓都未启用库位管理
        if (NUM_ZERO.equals(sourceWarehouseCacheMap.get(LOCATION_MANAGEMENT)) && NUM_ZERO.equals(targetWarehouseCacheMap.get(LOCATION_MANAGEMENT))) {
            //调出仓未启用库位管理，需要进行库存校验
            validAllocationInventory(allocation);
            // 更新调拨主单出库、入库数量
            omsAllocation.setUnitInboundQuantity(allocation.getUnitQuantity());
            omsAllocation.setInboundQuantity(allocation.getQuantity());
            omsAllocation.setUnitOutboundQuantity(allocation.getUnitQuantity());
            omsAllocation.setOutboundQuantity(allocation.getQuantity());
            omsAllocationItemList.stream().forEach(item -> {
                item.setUnitOutboundQuantity(item.getUnitQuantity());
                item.setOutboundQuantity(item.getQuantity());
                item.setUnitInboundQuantity(item.getUnitQuantity());
                item.setInboundQuantity(item.getQuantity());
            });
            omsAllocation.setAllocationItemList(omsAllocationItemList);

            omsAllocationItemService.saveOrUpdateBatch(omsAllocationItemList);
            omsOutboundService.saveByOmsAllocation(allocation);
            omsInboundService.saveByOmsAllocation(allocation, null);
        }
        // 调出仓启用库位管理，调入仓未启用库位管理
        if (NUM_ONE.equals(sourceWarehouseCacheMap.get(LOCATION_MANAGEMENT)) && NUM_ZERO.equals(targetWarehouseCacheMap.get(LOCATION_MANAGEMENT))) {
            //保存明细中的平均价格
            omsAllocation.setAllocationItemList(omsAllocationItemList);
            omsAllocationItemService.saveOrUpdateBatch(omsAllocationItemList);
            //TODO 注释代码完善
            deliveryService.saveByOmsAllocation(allocation);
        }
        // 调出仓不启用库位管理，调入仓启用库位管理
        if (NUM_ZERO.equals(sourceWarehouseCacheMap.get(LOCATION_MANAGEMENT)) && NUM_ONE.equals(targetWarehouseCacheMap.get(LOCATION_MANAGEMENT))) {
            //调出仓未启用库位管理，需要进行库存校验
            validAllocationInventory(allocation);
            omsAllocation.setUnitOutboundQuantity(allocation.getUnitQuantity());
            omsAllocation.setOutboundQuantity(allocation.getQuantity());
            omsAllocationItemList.stream().forEach(item -> {
                item.setUnitOutboundQuantity(item.getUnitQuantity());
                item.setOutboundQuantity(item.getQuantity());
            });
            omsAllocation.setAllocationItemList(omsAllocationItemList);
            omsAllocationItemService.saveOrUpdateBatch(omsAllocationItemList);
            omsOutboundService.saveByOmsAllocation(allocation);
            //TODO 注释代码完善
            receiveService.saveByOmsAllocation1(allocation);
        }
        // 调出仓、调入仓都启用库位管理
        if (NUM_ONE.equals(sourceWarehouseCacheMap.get(LOCATION_MANAGEMENT)) && NUM_ONE.equals(targetWarehouseCacheMap.get(LOCATION_MANAGEMENT))) {
            //保存明细中的平均价格
            omsAllocation.setAllocationItemList(omsAllocationItemList);
            omsAllocationItemService.saveOrUpdateBatch(omsAllocationItemList);
            //TODO 注释代码完善
            deliveryService.saveByOmsAllocation(allocation);
        }
    }

    public  void CheckDuplicatedata(OmsAllocation entity){
        List<OmsAllocationItem> omsAllocationItemList = entity.getAllocationItemList();
        Map<String, Object> validDuplication = new HashMap<>();
        String validKey;
        for (OmsAllocationItem e:omsAllocationItemList) {
            validKey = e.getGoodCode() + "-" + e.getBasicUnit();
            if(validDuplication.containsKey(validKey)){
                throw new ServiceException("存在重复的商品信息，请确认");
            }else{
                validDuplication.put(validKey, e);
            }
        }
    }
}
